﻿using System;
using System.Linq;
using System.Web.DynamicData;
using System.Web.UI;
using System.Text;

namespace NotAClue.ComponentModel.DataAnnotations
{
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
    public sealed class FileUploadAttribute : Attribute
    {
        /// <summary>
        /// Where to save files that are uploaded
        /// </summary>
        public String FileUploadPath { get; set; }

        /// <summary>
        /// File type to allow upload
        /// </summary>
        public String[] FileTypes { get; set; }

        /// <summary>
        /// The file extension of image (i.e. png or gif or jpg) to use for displaying file type icon
        /// </summary>
        public String DisplayImageType { get; set; }

        /// <summary>
        /// Where to find file type icons
        /// </summary>
        public String DisplayImageUrl { get; set; }

        /// <summary>
        /// Used to disable hyper link (Enabled by default)
        /// </summary>
        public Boolean DisableHyperlink { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether to [open link in new window].
        /// </summary>
        /// <value>if <c>true</c> [open link in new window].</value>
        public Boolean OpenInNewWindow { get; set; }

        /// <summary>
        /// Gets or sets the text column (STS specific).
        /// </summary>
        /// <value>The text column to store the extracted text.</value>
        public String FullTextSearchColumn { get; set; }

        /// <summary>
        /// Gets or sets the foreign key column.
        /// </summary>
        /// <value>The foreign key column.</value>
        public String ForeignKeyColumnName { get; set; }

        /// <summary>
        /// Gets or sets the file not present message.
        /// </summary>
        /// <value>The file not present message.</value>
        public String FileNotPresentMessage { get; set; }

        public String FileTypeString()
        {
            var stringFileTypes = new StringBuilder();
            foreach (var s in FileTypes)
            {
                stringFileTypes.Append(s + ",");
            }
            return stringFileTypes.ToString().Substring(0, stringFileTypes.Length - 1); ;
        }
    }
}